package Medium;

import java.util.HashSet;

public class LC1456 {
    public int maxVowels(String s, int k) {
        int maxVowels = 0, length = s.length();
        HashSet<Character> vowels = new HashSet<>();
        vowels.add('a');
        vowels.add('e');
        vowels.add('i');
        vowels.add('o');
        vowels.add('u');
        for (int i = 0; i < k; i++) {
            if (vowels.contains(s.charAt(i))) maxVowels++;
        }
        int nVowels = maxVowels;
        for (int i = 1; i <= length - 1 - k + 1; i++) {
            if (vowels.contains(s.charAt(i - 1))) nVowels--;
            if (vowels.contains(s.charAt(i + k - 1))) nVowels++;
            if (nVowels > maxVowels) maxVowels = nVowels;
        }

        return maxVowels;
    }
}
